#!/usr/bin/python3
# -*- coding: utf-8 -*-

# IQ编程

import os
import time

class Log:

	def __init__(self, path):
		# 检测目录，如果没有就创建目录
		if not os.path.isdir(os.path.dirname(path)):
			os.makedirs(os.path.dirname(path))

		self.path = path

	# 写文件
	def writeLog(self, msg):
		# 直接打开一个文件，如果文件不存在则创建文件
		with open(self.path, 'a+') as f:
			f.write(time.strftime("[%Y-%m-%d %H:%M:%S] ", time.localtime()) + str(msg) + '\r\n')
		

	# 读文件
	def readLog(self):
		if not os.path.isfile(self.path):
			return TypeError('没有文件')

		with open(self.path, 'r+', errors='ignore') as f:
			return f.read()
		

log = Log('C:/Users/Administrator/Desktop/tmp/test.txt')
# log.writeLog('反倒是更好')
print(log.readLog())